//package com.oliver.oliveraiagent.rag;
//
//import com.oliver.oliveraiagent.rag.LoveAppDocumentLoader;
//import jakarta.annotation.Resource;
//import org.springframework.ai.document.Document;
//import org.springframework.ai.embedding.EmbeddingModel;
//import org.springframework.ai.vectorstore.VectorStore;
//import org.springframework.ai.vectorstore.pgvector.PgVectorStore;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.jdbc.core.JdbcTemplate;
//
//import java.util.List;
//
//import static org.springframework.ai.vectorstore.pgvector.PgVectorStore.PgDistanceType.COSINE_DISTANCE;
//import static org.springframework.ai.vectorstore.pgvector.PgVectorStore.PgIndexType.HNSW;
//
///**
// * @version v1.0.0
// * @belongsProject: feng-ai-agent
// * @belongsPackage: com.qcdfz.fengaiagent.rag
// * @author: fgh
// * @description: PgVector配置加载类
// * @createTime: 2025-05-10 08:56
// */
//@Configuration
//public class PgVectorVectorStoreConfig {
//
//    @Resource
//    private LoveAppDocumentLoader loveAppDocumentLoader;
//    @Bean
//    public VectorStore pgVectorVectorStore(@Qualifier("postgresJdbcTemplate") JdbcTemplate jdbcTemplate,
//                                           EmbeddingModel dashscopeEmbeddingModel){
//        PgVectorStore vectorStore = PgVectorStore.builder(jdbcTemplate, dashscopeEmbeddingModel)
//        .dimensions(1536)                    // Optional: defaults to model dimensions or 1536
//        .distanceType(COSINE_DISTANCE)       // Optional: defaults to COSINE_DISTANCE
//        .indexType(HNSW)                     // Optional: defaults to HNSW
//        .initializeSchema(true)              // Optional: defaults to false
//        .schemaName("public")                // Optional: defaults to "public"
//        .vectorTableName("vector_store")     // Optional: defaults to "vector_store"
//        .maxDocumentBatchSize(10000)         // Optional: defaults to 10000
//        .build();
//
//        //  加载文档
////        List<Document> documents = loveAppDocumentLoader.loadMarkdowns();
////        int batchSize = 25; // 根据 DashScope 接口限制设置批次大小
////        for (int i = 0; i < documents.size(); i += batchSize) {
////            int end = Math.min(i + batchSize, documents.size());
////            List<Document> subList = documents.subList(i, end);
////            vectorStore.add(subList);
////        }
//
//        return vectorStore;
//    }
//}
